﻿using System;
using System.Xml.Serialization;

namespace ICalendar.CalendarProperties
{
    /// <summary>
    /// The property defines the relative priority for a calendar component.
    /// </summary>
    /// <value>0 is Highest priority and 9 is the lowest.</value>
    [Serializable]
    [XmlRoot("priority")]
    public class Priority : CalendarPropertyBase<int>
    {

        public Priority()
        {
            
        }

        public Priority(int value)
            : base(value)
        {
            
        }

        #region Overrides of CalendarPropertyBase<int>

        public override int Value
        {
            get
            {
                return base.Value;
            }
            set
            {
               // if (value != null &&   (value < 0 || value > 9))
                if (value < 0 || value > 9)
                throw new ArgumentOutOfRangeException("value", "This value must be between 0 and 9");
                base.Value = value;
            }
        }

        protected override void SetValue(string value)
        {
            Value = string.IsNullOrEmpty(value) ? 0 : Convert.ToInt32(value);
        }

        protected override string GetValue()
        {
            return Value.ToString();
        }

        protected override void SetParametersFromXParameters(XParameterCollection xparams)
        {
            
        }

        protected override XParameterCollection GetXParametersFromParameters()
        {
            return null;
        }

        protected override string[] GetXReservedParametersNames()
        {
            return null;
        }

        public static implicit operator Priority(int value)
        {
            return new Priority(value);
        }


        #endregion
    }
}
